
ShootController = {
	
	weaponType: 0,
	shoot: function(){
		if(this.weaponType == 0){
			GunVoiceContrller.play();
			this.checkTarget();
		}else if(this.weaponType == 1){
			if(!Character.moving){
				Character.moving = true;
				this.checkTarget();
			}
		}
	},	
	checkTarget : function(){
		
		var px = CameraController.lookAtPos.x - PlayMan.pos.x;
		var py = CameraController.lookAtPos.y - PlayMan.pos.y;
		var pz = CameraController.lookAtPos.z - PlayMan.pos.z;
		var cross = false;
		for(var i=0; i<EnemyModel.length; i++){
			var m =  PlayMan.pos.x - EnemyModel[i].pos.x;
			var n =  PlayMan.pos.y - EnemyModel[i].pos.y;
			var q =  PlayMan.pos.z - EnemyModel[i].pos.z;
			var r = EnemyModel[i].radius;
			
			if(this.weaponType == 0){
				cross = CrossCheck.LineShpere(m,n,q,r,px,py,pz);
			}else if(this.weaponType == 1){
				cross = CrossCheck.LineShpere(m,n,q,500,px,py,pz);
			}
			//Explosion.setExplosionPos(EnemyModel[i].pos.x, EnemyModel[i].pos.y, EnemyModel[i].pos.z);

			if(cross){
				if(this.weaponType == 0){
					TopPaneStatus.showNote("Nice Shoot!!!");
					Enemy.updateSingle(i,"c");
				}else if(this.weaponType == 1){
					Character.targetIndex = i;
					EnemyModel[i].speed.x += 450;
					EnemyModel[i].speed.y += 480;
				}
				break;
			}
		}
		if(!cross && this.weaponType == 1){
			Character.targetIndex = -1;
		}
		for(var j=0; j<TriggerModel.length; j++){
			var m = PlayMan.pos.x - TriggerModel[j].pos.x;
			var n = PlayMan.pos.y - TriggerModel[j].pos.y;
			var q = PlayMan.pos.z - TriggerModel[j].pos.z;
			var r = TriggerModel[j].radius;
			var cross = CrossCheck.LineShpere(m,n,q,r,px,py,pz);
			if(cross){
//				console.log("shoot the trigger");
				World.map.building[j].startRaise = !World.map.building[j].startRaise;
				//World.map.building[j].Rdirection = -World.map.building[j].Rdirection;
//				World.map.building[j].startRaise = true;
				break;
			}
		}
		
	},
	
}